import 'package:appflutterhomeschool/provider/provider_widget.dart';
import 'package:appflutterhomeschool/res/styles.dart';
import 'package:appflutterhomeschool/ui/widgets/notice/status_item_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/widgets.dart';
import 'package:appflutterhomeschool/view_model/notice/status_selection_list_view_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

///用户： ninetailedfox
///时间： 2020/6/17
///邮箱： 1037438704@qq.com
///功能： 接收人列表  未读和填写页面
class StatusSelectionListPage extends StatefulWidget {
  final int pageTag;

  StatusSelectionListPage({this.pageTag});

  @override
  _StatusSelectionListPageState createState() =>
      _StatusSelectionListPageState();
}

class _StatusSelectionListPageState extends State<StatusSelectionListPage> {

  @override
  Widget build(BuildContext context) {
    return ProviderWidget<StatusSelectionListViewModel>(
      model: StatusSelectionListViewModel(me: context, pageTag: widget.pageTag),
      onModelReady: (value) => value.initView(),
      builder: (context, viewModel, childe) {
        return DefaultTabController(
//          initialIndex: listTab.length,
          length: viewModel.listTab.length,
          child: Scaffold(
            backgroundColor: Colors.grey[100],
            appBar: AppBar(
              centerTitle: true,
              title: Text("接收人列表", style: TextStyles.textDarkBold43),
              brightness: Brightness.light,
              elevation: 1,
              leading: IconButton(
                icon: Icon(
                  Icons.arrow_back_ios,
                  size: ScreenUtil().setSp(40),
                  color: Colors.black,
                ),
                onPressed: () => Navigator.pop(context),
              ),
              bottom: TabBar(
                indicatorSize: TabBarIndicatorSize.label,
                indicatorWeight: 2,
                //选中的icon颜色
                indicatorColor: Colors.blue,
                isScrollable: false,
                labelColor: Colors.black,
                unselectedLabelColor: Colors.grey,
                tabs: viewModel.listTab,
              ),
            ),
            body: TabBarView(
              children: <Widget>[
                StatusTabBarViewWidget(leanth: 0),
                StatusTabBarViewWidget(leanth: 10,),
              ],
            ),
          ),
        );
      },
    );
  }
}

class StatusTabBarViewWidget extends StatelessWidget {
  final int pageTag;
  final int leanth;


  StatusTabBarViewWidget({this.pageTag,this.leanth});

  @override
  Widget build(BuildContext context) {
    StatusSelectionListViewModel selectionListViewModel = Provider.of(context);
    return SmartRefresher(
      enablePullDown: true,
      enablePullUp: true,
      footer: CustomFotterWidget(),
      header: ClassicHeader(),
      controller: selectionListViewModel.refreshController,
      onRefresh: selectionListViewModel.onRefresh,
      onLoading: selectionListViewModel.onLoading,
      child:leanth == 0 ? NullListWidget(tipsContnt: "全部已读",): Container(
        color: Colors.white,
        child: ListView.builder(
            itemCount: leanth,
            shrinkWrap: true,
            itemBuilder: (context, index) {
              return StatusItemWidget();
            }),
      ),
    );
  }
}
